'use strict';

const Controller = require('egg').Controller;

const cheerio  = require('cheerio');

class VmallController extends Controller {
  async homeIndex() {
    const { ctx } = this;
    let url = "https://m.vmall.com/huawei";
    let result = await this.ctx.curl(url);
    let htmlData = result.data.toString();

    const $ = cheerio.load(htmlData, { decodeEntities: false });
    let pro_sliders = [];
    $('.mod-productQuality .grid-list').each(function(index,item){
      let imgUrl = $(item).children('img').attr('src');
      console.log('imgUrl = ',$(item).children('.pic'));
      pro_sliders.push(imgUrl);
    });
    ctx.body = {
      pro_sliders: pro_sliders
    }
  };
}

module.exports = VmallController;
